package com.wpx.log.core.module;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.wpx.log.core.annotation.OpLogHandler;
import com.wpx.log.core.handler.OpCreateTimeLogHandler;
import com.wpx.log.core.handler.OpDescLogHandler;
import com.wpx.log.core.handler.OpExceptionLogHandler;
import com.wpx.log.core.handler.OpExecuteTimeLogHandler;
import com.wpx.log.core.handler.OpIpLogHandler;
import com.wpx.log.core.handler.OpNameLogHandler;
import com.wpx.log.core.handler.OpParameterLogHandler;
import com.wpx.log.core.handler.OpPathLogHandler;
import com.wpx.log.core.handler.OpStatusLogHandler;
import com.wpx.log.core.handler.OpTypeLogHandler;
import com.wpx.log.core.handler.OpUpdateLogHandler;
import com.wpx.log.core.handler.OpUserAgentLogHandler;


public class DefaultLog {
	
	/**
	 * 查询
	 */
	public static final int TYPE_QUERY = 1;
	/**
	 * 添加
	 */
	public static final int TYPE_ADD = 2;
	/**
	 * 修改
	 */
	public static final int TYPE_UPDATE = 3;
	/**
	 * 删除
	 */
	public static final int TYPE_DELETE = 4;
	/**
	 * 登录
	 */
	public static final int TYPE_LOGIN = 5;
	/**
	 * 登出
	 */
	public static final int TYPE_LOGIN_OUT = 6;
	
	/**
	 * 成功
	 */
	public static final int RESULT_SUCCESS = 1;
	/**
	 * 失败
	 */
	public static final int RESULT_FAIL = 2;
	/**
	 * 异常
	 */
	public static final int RESULT_ERROR = 3;
	/**
	 * IP拦截
	 */
	public static final int IP_NOT_ALLOW = 4;
	
	
	public static final Map<Integer, String> TYPE_MAP = new HashMap<Integer, String>();
	public static final Map<Integer, String> RESULT_MAP = new HashMap<Integer, String>();
	
	static {
		TYPE_MAP.put(TYPE_QUERY, "查询");
		TYPE_MAP.put(TYPE_DELETE, "删除");
		TYPE_MAP.put(TYPE_ADD, "添加");
		TYPE_MAP.put(TYPE_UPDATE, "修改");
		TYPE_MAP.put(TYPE_LOGIN, "登录");
		TYPE_MAP.put(TYPE_LOGIN_OUT, "登出");
		
		RESULT_MAP.put(RESULT_SUCCESS, "成功");
		RESULT_MAP.put(RESULT_FAIL, "失败");
		RESULT_MAP.put(RESULT_ERROR, "异常");
		RESULT_MAP.put(IP_NOT_ALLOW, "ip拦截");
	}
	
    protected Integer id;	
	
	@OpLogHandler(OpPathLogHandler.class)
	protected String url;
	
	@OpLogHandler(OpIpLogHandler.class)
	protected String ip;
	
	@OpLogHandler(OpNameLogHandler.class)
	protected String name;
	
	@OpLogHandler(OpStatusLogHandler.class)
	protected Integer status;
	
	@OpLogHandler(OpTypeLogHandler.class)
	protected Integer type;
	
	@OpLogHandler(OpDescLogHandler.class)
	protected String desc;
	
	@OpLogHandler(OpExceptionLogHandler.class)
	protected String excMsg;
	
	@OpLogHandler(OpParameterLogHandler.class)
	protected JSON param;
	
	@OpLogHandler(OpUserAgentLogHandler.class)
	protected String userAgent;
	
	@OpLogHandler(OpUpdateLogHandler.class)
	protected FieldUpdateInfo[] updateInfo;
	
	@OpLogHandler(OpCreateTimeLogHandler.class)
	protected Date createTime;
	
	@OpLogHandler(OpExecuteTimeLogHandler.class)
	protected Long executeTime;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getExcMsg() {
		return excMsg;
	}

	public void setExcMsg(String excMsg) {
		this.excMsg = excMsg;
	}

	public JSON getParam() {
		return param;
	}

	public void setParam(JSON param) {
		this.param = param;
	}

	public String getUserAgent() {
		return userAgent;
	}

	public void setUserAgent(String userAgent) {
		this.userAgent = userAgent;
	}

	public FieldUpdateInfo[] getUpdateInfo() {
		return updateInfo;
	}

	public void setUpdateInfo(FieldUpdateInfo[] updateInfo) {
		this.updateInfo = updateInfo;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Long getExecuteTime() {
		return executeTime;
	}

	public void setExecuteTime(Long executeTime) {
		this.executeTime = executeTime;
	}

	
	@Override
	public String toString() {
		return "\n"+this.getClass().getName()+" = "+JSON.toJSONString(this, true);
	}
	
}


